package com.xuetang9.t9.hotel.mapper.sql.impl;


/**
 * @author Pang
 */
public class SelectTimeSql {

    public static final String LASTWEEK = "LastWeek";
    public static final String THISWEEK = "ThisWeek";
    public static final String NEXTWEEK = "NextWeek";

    public static final String THISDAY = "ThisDay";
    public static final String TOMORROWDAY = "TomorrowDay";
    public static final String AFTERDAY = "AfterDay";

    //周

    //上周
    private static String getLastWeek(String column){
        return "YEARWEEK(DATE_FORMAT("+column+",'%Y-%m-%d'),1) = YEARWEEK(NOW())";
    }
    //本周
    private static String getThisWeek(String column){
        return "YEARWEEK(DATE_FORMAT("+column+",'%Y-%m-%d'),1) = YEARWEEK(NOW(),1)";
    }
    //下周
    private static String getNextWeek(String column){
        return "YEARWEEK(DATE_FORMAT("+column+",'%Y-%m-%d'),1) = YEARWEEK(NOW(),1)+1";
    }


    //天

    //今天
    private static String getThisDay(String column){
        return "TO_DAYS("+column+") = TO_DAYS(NOW())";
    }
    //明天
    private static String getTomorrowDay(String column){
        return "TO_DAYS("+column+") = TO_DAYS(NOW()) + 1";
    }
    //后天
    private static String getAfterDay(String column){
        return "TO_DAYS("+column+") = TO_DAYS(NOW()) + 2";
    }


    /**
     * 获取时间的sql语句
     * @param key 要查询的时间
     * @param column 数据库字段名称
     * @return
     */
    public static String getSql(String key,String column){
        return key.equals(LASTWEEK) == true?getLastWeek(column):
                    key.equals(THISWEEK) == true?getThisWeek(column):
                            key.equals(NEXTWEEK) == true?getNextWeek(column):
                                    key.equals(THISDAY) == true?getThisDay(column):
                                        key.equals(TOMORROWDAY) == true?getTomorrowDay(column):
                                                key.equals(AFTERDAY) == true?getAfterDay(column):null;
    }


}
